package com.kingstar.ceres.data.strategy;

import com.kingstar.ceres.data.facade.IDataInitFacade;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class DataInitFactory {

    private Map<String, IDataInitFacade> dataInitFacadeMap=new HashMap<>();

    public void register(String fileType,IDataInitFacade dataInitFacade){
        dataInitFacadeMap.put(fileType,dataInitFacade);
    }
    public boolean process(String fileType,String param) throws Exception {
        log.info("DataInitFactory select facade,fileType:{},param:{}",fileType,param);
        if(dataInitFacadeMap.isEmpty()){
            log.info("未开启数据导入功能");
            return Boolean.TRUE;
        }
        IDataInitFacade dataInitFacade = dataInitFacadeMap.get(fileType);
        if (dataInitFacade==null){
            log.error("无效的文件类型");
            return Boolean.FALSE;
        }
        return dataInitFacade.execute(param,fileType);
    }
}